﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game.Foundation.ChineseChess
{
    public class Xiang : ChessmanBase
    {
        private int _originalYLocation;

        public Xiang(Chessboard board, Camp camp, string text, int y)
            : base(board, camp, text)
        {
            this._originalYLocation = y;
        }

        public override bool CanMoveTo(int xLocation, int yLocation)
        {
            if (Math.Abs(yLocation - this._originalYLocation) > 4) return false;

            int xoffset = xLocation - this.XLocation;
            int yoffset = yLocation - this.YLocation;
            if (Math.Abs(xoffset) == 2 && Math.Abs(yoffset) == 2)
            {
                int xmiddle = (xLocation + this.XLocation) / 2;
                int ymiddle = (yLocation + this.YLocation) / 2;

                return this._board.GetChessman(xmiddle, ymiddle) == null;
            }

            return false;
        }
    }
}
